import { defHttp } from '@/utils/http/axios';
import {
  TabConfigCatPageParams,
  TabConfigCatPageListGetResultModel,
  SettingParams,
  SettingPageParams,
  SettingPageListGetResultModel,
  SaveBasicsParams,
  AdminParams,
  AdminPageParams,
  AdminPageListGetResultModel,
  DeptParams,
  DeptPageParams,
  DeptListGetResultModel,
  MenusParams,
  MenuPageParams,
  MenuListGetResultModel,
  RoleParams,
  RolePageParams,
  RoleListGetResultModel,
  RolePageListGetResultModel,
  RoleSelectListGetResultModel,
  StoragePageParams,
  StorageListGetResultModel,
  StorageParams,
  StorageDomainParams,
  StorageConfigParams,
} from './model/settingModel';

enum Api {
  // 配置分类列表
  TabConfigCatList = '/setting/config_cat/list',

  // 配置列表
  SettingList = '/setting/config/list',
  // 添加配置
  CreateSetting = '/setting/config/create',
  // 更新配置
  UpdateSetting = '/setting/config/update',
  // 删除配置
  DeleteSetting = '/setting/config/delete',

  // 获取分类配置列表
  ConfigList = '/setting/config_list',
  // 保存修改配置
  SaveBasicsConfig = '/setting/config/save_basics',

  // 存储配置
  SettingImage = '/setting/config/image',
  // 切换存储类型
  SaveType = '/setting/config/storage/save_type',
  // 云存储列表
  StorageList = '/setting/config/storage',
  // 获取空间区域下拉数据
  StorageSelectList = '/setting/config/storage/select_list',
  // 创建云存储数据
  CreateStorage = '/setting/config/storage/create',
  // 同步云存储空间
  SyncsStorage = '/setting/config/storage/syncs',
  // 获取云配置信息
  ConfigStorage = '/setting/config/storage/config_form',
  // 保存云存储配置
  SaveConfigStorage = 'setting/config/storage/config',
  // 获取修改云存储域名
  UpdateStorageDomain = '/setting/config/storage/domain',
  // 修改云存储状态
  SetStorageStatus = '/setting/config/storage/status',
  // 删除云存储
  DeleteStorage = '/setting/config/storage/delete',

  // 管理员列表
  AdminList = '/setting/admin/list',
  // 添加管理员
  CreateAdmin = '/setting/admin/create',
  // 修改管理员
  UpdateAdmin = '/setting/admin/update',
  // 删除管理员
  DeleteAdmin = '/setting/admin/delete',
  // 设置管理员状态
  SetAdminStatus = '/setting/admin/set_status',
  // 检测用户名是否可用
  CheckUsername = '/setting/admin/usernameExist',

  // 角色列表
  RolePageList = '/setting/role/list',
  // 创建角色
  CreateRole = '/setting/role/create',
  // 更新角色
  UpdateRole = '/setting/role/update',
  // 删除角色
  DeleteRole = '/setting/role/delete',
  // 设置角色状态
  SetRoleStatus = '/setting/role/set_status',
  // 角色下拉框
  RoleSelectList = '/setting/role/search_roles',
  // 权限列表
  RoleAllMenusList = '/setting/role/role_menus',

  // 菜单列表
  MenuList = '/setting/menus/list',
  // 创建菜单
  CreateMenus = '/setting/menus/create',
  // 更新菜单
  UpdateMenus = '/setting/menus/update',
  // 删除菜单
  DeleteMenus = '/setting/menus/delete',
  // 设置菜单状态
  SetMenusStatus = '/setting/menus/set_show',

  // 部门列表
  DeptList = '/setting/dept/list',
  // 创建部门
  CreateDept = '/setting/dept/create',
  // 更新部门
  UpdateDept = '/setting/dept/update',
  // 设置角色状态
  SetDeptStatus = '/setting/dept/set_status',
  // 删除部门
  DeleteDept = '/setting/dept/delete',

  // 系统日志
  LogList = '/setting/log',
  // 登录日志
  LoginLogList = '/setting/log/login',
}

/**
 * 配置分类列表
 * @param params
 * @returns
 */
export const getTabConfigCatList = (params: TabConfigCatPageParams) =>
  defHttp.get<TabConfigCatPageListGetResultModel>({
    url: Api.TabConfigCatList,
    params,
  });

/**
 * 配置列表
 * @param params
 * @returns
 */
export const getSettingList = (params: SettingPageParams) =>
  defHttp.get<SettingPageListGetResultModel>({
    url: Api.SettingList,
    params,
  });

/**
 * 添加配置
 * @param params
 * @returns
 */
export const createSetting = (params: SettingParams) =>
  defHttp.post({ url: Api.CreateSetting, params });

/**
 * 更新配置
 * @param params
 * @returns
 */
export const updateSetting = (id: number | string, params: SettingParams) =>
  defHttp.put({ url: `${Api.UpdateSetting}/${id}`, params });

/**
 * 删除配置
 * @param params
 * @returns
 */
export const deleteSetting = (id: number | string) =>
  defHttp.delete({ url: `${Api.DeleteSetting}/${id}` });

/**
 * 获取分类配置列表  tabId
 * @param params
 * @returns
 */
export const getConfigList = (tabId: number | string) =>
  defHttp.get({
    url: `${Api.ConfigList}/${tabId}`,
  });

/**
 * 保存配置
 * @param params
 * @returns
 */
export const saveBasicsConfig = (params: SaveBasicsParams) =>
  defHttp.post({
    url: `${Api.SaveBasicsConfig}`,
    params,
  });

/**
 * 管理员列表
 * @param params
 * @returns
 */
export const getAdminList = (params: AdminPageParams) =>
  defHttp.get<AdminPageListGetResultModel>({ url: Api.AdminList, params });

/**
 * 创建管理员
 * @param params
 * @returns
 */
export const createAdmin = (params: AdminParams) => defHttp.post({ url: Api.CreateAdmin, params });

/**
 * 更新管理员
 * @param id
 * @param params
 * @returns
 */
export const updateAdmin = (id: number | string, params: AdminParams) =>
  defHttp.put({ url: `${Api.UpdateAdmin}/${id}`, params });

/**
 * 设置管理员状态
 * @param id
 * @param status
 * @returns
 */
export const setAdminStatus = (id: number | string, status: number | string) =>
  defHttp.put({ url: `${Api.SetAdminStatus}/${id}/${status}` });

/**
 * 删除管理员
 * @param id
 * @returns
 */
export const deleteAdmin = (id: number | string) =>
  defHttp.delete({ url: `${Api.DeleteAdmin}/${id}` });

/**
 * 检测账号是否存在
 * @param username
 * @returns
 */
export const checkUsername = (username: string) =>
  defHttp.post({ url: Api.CheckUsername, params: { username } }, { errorMessageMode: 'none' });

/**
 * 角色列表
 * @param params
 * @returns
 */
export const getRoleListByPage = (params?: RolePageParams) =>
  defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params });

/**
 * 添加角色
 * @param id
 * @param params
 * @returns
 */
export const createRole = (id: number | string, params: RoleParams) =>
  defHttp.post({ url: `${Api.CreateRole}/${id}`, params });

/**
 * 修改角色
 * @param id
 * @param params
 * @returns
 */
export const updateRole = (id: number | string, params: RoleParams) =>
  defHttp.put({ url: `${Api.UpdateRole}/${id}`, params });

/**
 * 设置角色状态
 * @param id
 * @param status
 * @returns
 */
export const setRoleStatus = (id: number | string, status: number | string) =>
  defHttp.put({ url: `${Api.SetRoleStatus}/${id}/${status}` });

/**
 * 删除角色
 * @param id
 * @returns
 */
export const deleteRole = (id: number) => defHttp.delete({ url: `${Api.DeleteRole}/${id}` });

/**
 * 下拉角色列表
 * @returns
 */
export const getRoleSelectList = () =>
  defHttp.get<RoleSelectListGetResultModel>({ url: Api.RoleSelectList });

/**
 * 权限列表
 */
export const getRoleAllMenusList = () =>
  defHttp.get<RoleListGetResultModel>({ url: Api.RoleAllMenusList });

/**
 * 菜单列表
 * @param params
 * @returns
 */
export const getMenuList = (params?: MenuPageParams) =>
  defHttp.get<MenuListGetResultModel>({ url: Api.MenuList, params });

/**
 * 创建菜单
 * @param params
 * @returns
 */
export const createMenus = (params: MenusParams) => defHttp.post({ url: Api.CreateMenus, params });

/**
 * 更新菜单
 * @param id
 * @param params
 * @returns
 */
export const updateMenus = (id: number, params: MenusParams) =>
  defHttp.put({ url: `${Api.UpdateMenus}/${id}`, params });

/**
 * 删除菜单
 */
export const deleteMenus = (id: number | string) =>
  defHttp.delete({ url: `${Api.DeleteMenus}/${id}` });

/**
 * 设置菜单状态
 * @param id
 * @param is_show
 * @returns
 */
export const setMenusStatus = (id: number | string, is_show: number | string) =>
  defHttp.put({ url: `${Api.SetMenusStatus}/${id}/${is_show}` });

/**
 * 部门列表
 * @param params
 * @returns
 */
export const getDeptList = (params?: DeptPageParams) =>
  defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });

/**
 * 添加部门
 * @param id
 * @param params
 * @returns
 */
export const createDept = (params: DeptParams) => defHttp.post({ url: Api.CreateDept, params });

/**
 * 修改部门
 * @param id
 * @param params
 * @returns
 */
export const updateDept = (id: number | string, params: RoleParams) =>
  defHttp.put({ url: `${Api.UpdateDept}/${id}`, params });

/**
 * 设置部门状态
 * @param id
 * @param status
 * @returns
 */
export const setDeptStatus = (id: number | string, status: number | string) =>
  defHttp.put({ url: `${Api.SetDeptStatus}/${id}/${status}` });

/**
 * 删除部门
 */
export const deleteDept = (id: number | string) =>
  defHttp.delete({ url: `${Api.DeleteDept}/${id}` });

/**
 * 获取分类配置列表
 * @param params
 * @returns
 */
export const getSettingImage = () =>
  defHttp.get({
    url: `${Api.SettingImage}`,
  });

/**
 * 切换存储类型
 * @param type 1 本地储存，2 七牛云储存，3 阿里云储存，4 腾讯云储存，5 京东云储存，6 华为云储存，7 天翼云储存
 * @returns
 */
export const setSaveType = (type: number | string) =>
  defHttp.get({
    url: `${Api.SaveType}/${type}`,
  });

/**
 * 云存储列表
 * @param type 2 七牛云储存，3 阿里云储存，4 腾讯云储存，5 京东云储存，6 华为云储存，7 天翼云储存
 * @returns
 */
export const getStorageList = (params?: StoragePageParams) =>
  defHttp.get<StorageListGetResultModel>({ url: Api.StorageList, params });

/**
 * 获取空间区域下拉数据
 * @param type 2 七牛云储存，3 阿里云储存，4 腾讯云储存，5 京东云储存，6 华为云储存，7 天翼云储存
 * @returns
 */
export const getStorageSelectList = (type: number | string) =>
  defHttp.get({
    url: `${Api.StorageSelectList}/${type}`,
  });

/**
 * 创建云存储数据
 * @param type 2 七牛云储存，3 阿里云储存，4 腾讯云储存，5 京东云储存，6 华为云储存，7 天翼云储存
 * @param params
 * @returns
 */
export const createStorage = (type: number | string, params: StorageParams) =>
  defHttp.post({ url: `${Api.CreateStorage}/${type}`, params });

/**
 * 同步云存储列表
 * @param type 2 七牛云储存，3 阿里云储存，4 腾讯云储存，5 京东云储存，6 华为云储存，7 天翼云储存
 * @returns
 */
export const getSyncsStorage = (type: number | string) =>
  defHttp.put({
    url: `${Api.SyncsStorage}/${type}`,
  });

/**
 * 获取云配置信息
 * @param type 2 七牛云储存，3 阿里云储存，4 腾讯云储存，5 京东云储存，6 华为云储存，7 天翼云储存
 * @returns
 */
export const getConfigStorage = (type: number | string) =>
  defHttp.get({
    url: `${Api.ConfigStorage}/${type}`,
  });

/**
 * 保存云存储配置
 * @param id
 * @param params
 * @returns
 */
export const saveConfigStorage = (params: StorageConfigParams) =>
  defHttp.post({ url: `${Api.SaveConfigStorage}`, params });

/**
 * 获取修改云存储域名
 * @param id
 * @returns
 */
export const getUpdateStorageDomain = (id: number | string) =>
  defHttp.get({
    url: `${Api.UpdateStorageDomain}/${id}`,
  });

/**
 * 修改云存储域名
 * @param id
 * @param params
 * @returns
 */
export const updateStorageDomain = (id: number | string, params: StorageDomainParams) =>
  defHttp.post({ url: `${Api.UpdateStorageDomain}/${id}`, params });

/**
 * 修改云存储状态
 * @param id
 * @returns
 */
export const SetStorageStatus = (id: number | string) =>
  defHttp.put({
    url: `${Api.SetStorageStatus}/${id}`,
  });

/**
 * 删除云存储
 * @param params
 * @returns
 */
export const deleteStorage = (id: number | string) =>
  defHttp.delete({ url: `${Api.DeleteStorage}/${id}` });
